#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define N 4

double f(double argv[N],double x){
    double sum=0;
    int i;
    for (i=0;i<N;i++) sum+=argv[i]*pow(x,N-i-1);
    return sum;
}

double df(double argv[N],double x){
    double sum=0;
    int i;
    for (i=0;i<N-1;i++) sum+=(N-i-1)*argv[i]*pow(x,N-i-2);
    return sum;
}

double solut(double argv[N]){
    double n,m=0;
    do{
        n=m;
        m=n-f(argv,n)/df(argv,n);
    } while (fabs(n-m)>10E-5);
    return (n+m)/2;
}

int main(){
    // 牛顿迭代法求三次函数的根
    double argv[N]={0},s;
    int i;
    printf("ax^3+bx^2+cx+d=0,input a b c d:\n");
    for (i=0;i<N;i++) scanf("%lf",&argv[i]);
    // printf("%lf",f(argv,1));
    s = solut(argv);
    printf("soluation x=%lf\n",s);
    return 0;
}